/*  1:   */ package org.jetbrains.io;
/*  2:   */ 
/*  3:   */

import io.netty.channel.*;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.util.concurrent.ImmediateEventExecutor;
import org.jetbrains.annotations.NotNull;

import java.util.concurrent.TimeUnit;

/*  4:   */
/*  5:   */
/*  6:   */
/*  7:   */
/*  8:   */
/*  9:   */
/* 10:   */
/* 11:   */
/* 12:   */
/* 13:   */
/* 14:   */
/* 15:   */
/* 16:   */ 
/* 17:   */ @ChannelHandler.Sharable
/* 18:   */ public final class ChannelRegistrar
/* 19:   */   extends ChannelHandlerAdapter
/* 20:   */ {
/* 21:13 */   private final ChannelGroup a = new DefaultChannelGroup(ImmediateEventExecutor.INSTANCE);
/* 22:   */   
/* 23:   */   public boolean isEmpty()
/* 24:   */   {
/* 25:16 */     return this.a.isEmpty();
/* 26:   */   }
/* 27:   */   
/* 28:   */   public void add(@NotNull Channel paramChannel)
/* 29:   */   {
/* 30:20 */     if (paramChannel == null) {
/* 31:20 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/io/ChannelRegistrar", "add" }));
/* 32:   */     }
/* 33:20 */     assert ((paramChannel instanceof ServerChannel));
/* 34:21 */     this.a.add(paramChannel);
/* 35:   */   }
/* 36:   */   
/* 37:   */   public void channelActive(ChannelHandlerContext paramChannelHandlerContext)
/* 38:   */     throws Exception
/* 39:   */   {
/* 40:27 */     this.a.add(paramChannelHandlerContext.channel());
/* 41:   */     
/* 42:29 */     super.channelActive(paramChannelHandlerContext);
/* 43:   */   }
/* 44:   */   
/* 45:   */   public void close()
/* 46:   */   {
/* 47:33 */     close(true);
/* 48:   */   }
/* 49:   */   
/* 50:   */   public void close(boolean paramBoolean)
/* 51:   */   {
/* 52:37 */     EventLoopGroup localEventLoopGroup = null;
/* 53:38 */     if (paramBoolean) {
/* 54:39 */       for (Channel localChannel : this.a) {
/* 55:40 */         if ((localChannel instanceof ServerChannel))
/* 56:   */         {
/* 57:41 */           localEventLoopGroup = localChannel.eventLoop().parent();
/* 58:42 */           break;
/* 59:   */         }
/* 60:   */       }
/* 61:   */     }
/* 62:   */     try
/* 63:   */     {
/* 64:48 */       this.a.close().awaitUninterruptibly(30L, TimeUnit.SECONDS);
/* 65:   */     }
/* 66:   */     finally
/* 67:   */     {
/* 68:51 */       if (localEventLoopGroup != null) {
/* 69:52 */         localEventLoopGroup.shutdownGracefully();
/* 70:   */       }
/* 71:   */     }
/* 72:   */   }
/* 73:   */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.io.ChannelRegistrar

 * JD-Core Version:    0.7.0.1

 */